0

I am using the following code to retrieve URL params into a JavaScript variable.

function getUrlParams() {
  var params = {};
  window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) {
    params[key] = value;
  });
  return params;
}
var vName = getUrlParams()["vName"];

I have to set vName into h:inputText.

document.getElementById("Forid:Fldid").value = vName; // didn't work

I am working on Facelets.

pb2q
  • 58,613
  • 19
  • 146
  • 147
p_anantha
  • 352
  • 1
  • 2
  • 12

1 Answers1

1

Don't do it the hard way. Use <f:viewParam>.

<f:metadata>
    <f:viewParam name="vName" value="#{bean.vName}" />
</f:metadata>
...
<h:form>
    <h:inputText value="#{bean.vName}" />
    ...
</h:form>

with

@ManagedBean
@ViewScoped
public class Bean {

    private String vName;

    // Getter+setter.
}

That's all.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555