2

I have the following event of preRenderView type to execute a method before loading the page:

<f:event listener="#{aprobacionFlujoController.preRender}" type="preRenderView" />

I need to send a parameter to that listener, which is the best way to do it, probe as follows:

<f:metadata>
    <f:event listener="#{aprobacionFlujoController.preRender}" type="preRenderView" />
    <f:attribute name="myid" value="true" />
</f:metadata>

Controller

public void retrieveData(ComponentSystemEvent event) {
    String id = (String) event.getComponent().getAttributes().get("myid");
}

But getAttributes() method returns empty.

1 Answer 1

1

Well, if you are using JSF 2.2 then you can use the <f:viewAction /> to perform tasks before page is rendered since what you are trying to achieve from what I can tell is to retrieve data from DB to display, in other words to have a dynamic web page.

In your facelets page:

<h:head>
  <f:metadata>
    <f:viewParam name="parameter_id" value="#{yourbean.searchId}" />
    <f:viewAction action="#{yourbean.getInfo}" />
  </f:metadata>
</h:head>

What the viewParam does is to set the property passed in the value attribute; this property comes as an HTTP GET REQUEST parameter, e.g:

yourwebsite.com/yourpage.xhtml?parameter_id=parameter_value

In your Managed Baen you just have a method that performs the data extraction using the property:

@NAmed
@your_scope
public class YourBean implements Serializable{

   private String searchId;

   public void getInfo(){
     yourService.getData(searchId);
    // ... the rest .... 
  }

 // setter & getter for searchId
}

If you want to do it your way, asuming its because you're using JSF 2.1 | 2.0 then maybe try this to get the request parameters:

String parameter = ((Map<String,String>)Facescontext.getExternalContext().getRequestParameterMap()).get("your_parameter_name");
0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.