0

Consider the following fragment of the HtmlBasicRenderer class:

 Map<String, String> requestMap =
              context.getExternalContext().getRequestParameterMap();
        // Don't overwrite the value unless you have to!
 String newValue = requestMap.get(clientId);
 if (newValue != null) {
      setSubmittedValue(component, newValue);
      if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE,
                   "new value after decoding {0}",
                   newValue);
      }
 }

The fragment is being appeard within the decode(FacesContext context, UIComponent component) method which is responsible for extracting request parameters and assigning it to components during the Apply Request Phase.

My question is about how this request parameter are generated? If we have simple html-form and standard html inputs inside it like that:

<form method="POST">
    <input name="name" value="value" />
</form>

we'll get the name=value parameter pair.

So, the only way for us to specify the request parameter key for a component we're writing is to specify the name attribute of the element within the encode method of it's renderer. Once we did that, we can get access to the corresponding parameter from the decode method.

Update: I'm writing a component inherited from UISelectOne but the selected item may contain more the one input field (two in specifiec). Its declaration will look something like the following (details seemed unimportand were ommited):

<stcomutil:selectOne key="#{myBean.key}" value="#{myBean.value}">
    <stcomutil:selectOneItem />
    <stcomutil:selectOneItem />
    <stcomutil:selectOneItem />
</stcomutil:selectOne>

Where <stcomutil:selectOneItem /> is rendered as two input type="text":

enter image description here.

        ^                       ^
        |                       |
        |                       |
   the key field          the value field

So, in fact I will have 3 rows of such inputs and I need to process the only row user type in. Again, I omit the details with disabling inputs and so forth.

What I want to learn: To process additional value input (convert, validate, update, etc) I just need to specify the name attribute for that additional input and then extract it at the Apply request phase, right? Also, at the Update model phase I have to explcitily extract the ValueExpression object for that binding with the getValueExpression and assign the value to it with the setValue method.

user3663882
  • 6,957
  • 10
  • 51
  • 92
  • You dug really deep into the renderer stuff yet your html is not jsf compliant. I suspect you come from e.g. a php background and want to process things in the same way as is done there. It's not, well, not needed, but your xhtml file should be in the jsf way. So use h:form and h:input or the html5 'compatible' way if you want. More on both can be found easily using google. But you better start with a basic jsf tutorial. Or do I totally fail to understand your question? – Kukeltje Aug 09 '15 at 08:17
  • I fail to understand/see the concrete question. You seem to already have answered the question yourself in the last paragraph. Please clarify. – BalusC Aug 09 '15 at 08:42
  • @BalusC Added some details about what I'm actually trying to achieve. Maybe I'm on the wrong way ever... – user3663882 Aug 09 '15 at 09:10
  • @Kukeltje Actually not execatly... but I'm pretty new to JSF and in my specifiec case I decided that I really need to write custom (inhertied from UISelectOne) component class. Custom renderer or composite component cannot give me the behavior I need (from my standpoint)... – user3663882 Aug 09 '15 at 09:14
  • Ah... You're most likely looking for a composite component. Is this acceptable as dupe? http://stackoverflow.com/q/17235721 – BalusC Aug 09 '15 at 09:34
  • @BalusC So it's not neccesary to write custom renderer from scratch, We can attache a composite component implementation to our compoenent class istead (with the `componentType` attribute). Is that what you meant? – user3663882 Aug 09 '15 at 09:40
  • A custom component and renderer can also, it's only a bit more of work when the functionality can already be achieved with a composite. See also a.o. http://stackoverflow.com/q/6822000 – BalusC Aug 09 '15 at 09:41

0 Answers0