Use params of loadNetzkeComponent in configuration

Is it possible to pass extra parameters to "loadNetzkeComponent" and use them in the compnent configuration?

Example:

JavaScript:
this.loadNetzkeComponent({name: 'Erp::OrderPanel', container: 'workspace', params: { orderId: 1 }, scope: this });
Ruby:
class Erp::OrderPanel < Netzke::Base
  # ...
  def configuration(params)
    super.merge(
      scope: { order_id: params[:order_id] }
    )
  end
  # ...
end

I know, there is no param attribute for the configuration method, but is there a way to do something like that?

Answers


You could use session (or component_session) store to pass parameters to configuration.

session[:order_id] = params[:order_id]

Then in configuration:

def configuration(params)
    super.merge(
      scope: { order_id: session[:order_id] }
    )
  end

1) Because it's not safe to pass config params directly from JavaScript, one way to do it is to override the deliver_component endpoint in the parent component (the one calling loadNetzkeComponent), where you could do eventual security checks of the passed parameters, and then override the component configuration. An example of this can be found in the test app for netzke-core: https://github.com/nomadcoder/netzke-core/blob/master/test/core_test_app/app/components/component_loader.rb#L98

2) The method suggested by Dmytro would probably require an extra endpoint call on the parent just before loading the child component. In that endpoint you would store the require param in the session - this way you'll make sure that param is remembered every time the loaded child component communicates to the server. The first method doesn't provide that, because the passed parameter is only used once - at the moment of loading the component - and then "forgotten".

Depending on your requirements, pick one of the two.


Need Your Help

Passing Data between View Controllers : from uitableview to a details view controller

ios xcode uitableview uistoryboard

I am using IOS 5 and Storyboard coding. I have built an application in which i have a tableView connected to a sqlite database with a search bar.

How to manage server user session within client side single page app

javascript jquery jsp session single-page-application

I've been fumbling around with different client side technologies, like AngularJS, EmberJS, even trying to use straight JQuery and figure out how to use ReactJS with it. That aside, my goal is to b...