Wicket autocomplete with comboboxes and IE6 - internet-explorer-6

I have form in which there is AutoCompleteTextField and two combo boxes (DropDowns in wicket).
When drop down for autocomplete is shown, combo boxes are hidden in IE6.
My test page code is:
package net.betlista;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.apache.wicket.Session;
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
public class AutoCompleteAndDropDownTestPage extends WebPage {
public AutoCompleteAndDropDownTestPage() {
final DropDownChoice<Integer> drop1 = new DropDownChoice<Integer>("drop1", getNewList(15));
drop1.setOutputMarkupId(true);
final DropDownChoice<Integer> drop2 = new DropDownChoice<Integer>("drop2", getNewList(10));
drop2.setOutputMarkupId(true);
Session.get().setLocale(Locale.ENGLISH);
final AutoCompleteTextField<Integer> auto = new AutoCompleteTextField<Integer>("auto", new Model<Integer>(null)) {
#Override
protected Iterator<Integer> getChoices(final String input) {
return getNewList(20).iterator();
}
};
add(auto);
add(drop1);
add(drop2);
add(new TextField<String>("text"));
}
private static List<Integer> getNewList(final int upTo) {
final LinkedList<Integer> list = new LinkedList<Integer>();
for (int i = 0; i < upTo; i++) {
list.add(i);
}
return list;
}
}
test page markup is
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form>
<input type="text" wicket:id="auto"/><br>
<select wicket:id="drop1"></select><br>
<select wicket:id="drop2"></select><br>
<input type="text" wicket:id="text"/><br>
</form>
</body>
</html>
Wicket does NOT support IE6, so I'm looking for a workaround.

You should try to upgrade to 6.7.0, this issue sees fixed : https://issues.apache.org/jira/browse/WICKET-4893

Related

Can a list of type<string> containing #Html.ActionLinks be passed as the Model from a Controller to a View?

I have a controller that builds Html from a database and stores each html sequence as a string in a list of strings. This list of strings is passed to a View as its model. A Razor foreach loop outputs the Html in the View as follows:
#{
foreach (var Line in Model)
{
var myHTML = new HtmlString(#Line);
#myHTML
}
}
This logic produces valid hyperlinks for < a href=”URL” > Go To URL < /a> type Html commands.
I have attempted to create #Html.ActionLinks using this paradigm but the Razor code loop interprets #Html.ActionLink as text, not as a command with a hyperlink. Is there a way to accomplish this?
Here is the Index() Action used to test:
public ActionResult Index()
{
List<string> HTMLList = new List<string>();
string workURL;
string work;
workURL = "http://stackoverflow.com";
work = "" + "This will Work" + "" ;
HTMLList.Add(work);
HTMLList.Add("<br/><br/>");
work = "#Html.ActionLink(\"This Will Be Text not a hyperlink\",\"Display\",\"PDF\")";
HTMLList.Add(work);
//HTMLList.Add(work2.HtmlEncode());
return View("Jay",HTMLList);
}
Here is the View file:
<!DOCTYPE html>
#{
ViewBag.Title = "Jay";
}
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Jay</title>
</head>
<body>
<div id="wrapper">
<nav>
#{
foreach (var Line in Model)
{
var myHTML = new HtmlString(#Line);
#myHTML
}
}
<br />
</nav>
</div>
</body>
</html>

display message using JSF

I'm completely new in JSF. I'm using this tutorial: https://www.tutorialspoint.com/jsf
According to it I created a first project. Here's the Java code:
package com.tutorialspoint.test;
import javax.faces.bean.ManagedBean;
#ManagedBean(name = "helloWorld", eager = true)
public class HelloWorld {
public HelloWorld() {
System.out.println("HelloWorld started!");
}
public String getMessage() {
return "Hello World!";
}
}
this is home.xhtml file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>JSF Tutorial!</title>
</head>
<body>
#{helloWorld.getMessage()}
</body>
</html>
when I enter this address in my browser: http://localhost:8080/helloworld/home.jsf the tab's title "JSF Tutorial!" is displayed but the content (the text "Hello World" not. Could I ask you for some hints what can be missing?
If you need some more information/code from other files, just let me know.
BTW, I'm using Wildfly 10.1.0 as an application server where I deploy the updated .war file.
Thanks in advance.

Is there any technical advantage of actionListner attribute over action attribute in h:commandButton?

In the core JSF book (page 312) the author said about that:
Note that an action alone cannot implement that behavior—an action can
navigate to the appropriate page, but it cannot determine the
appropriate page because it knows nothing about the image button in
the user interface or the mouse click.
below is the index.xhtml and the ManagedBean used on that example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<h:outputStylesheet library="css" name="styles.css"/>
<title>#{msgs.indexWindowTitle}</title>
</h:head>
<h:body>
<span class="instructions">#{msgs.instructions}</span>
<h:form>
<h:commandButton image="/resources/images/mountrushmore.jpg"
styleClass="imageButton"
actionListener="#{rushmore.handleMouseClick}"
action="#{rushmore.navigate}"/>
</h:form>
</h:body>
</html>
Managed Bean:
package com.corejsf;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.Map;
import javax.faces.bean.ManagedBean;
// or import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
// or import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
#ManagedBean // or #Named
#RequestScoped
public class Rushmore {
private String outcome = null;
private Rectangle washingtonRect = new Rectangle(70, 30, 40, 40);
private Rectangle jeffersonRect = new Rectangle(115, 45, 40, 40);
private Rectangle rooseveltRect = new Rectangle(135, 65, 40, 40);
private Rectangle lincolnRect = new Rectangle(175, 62, 40, 40);
public void handleMouseClick(ActionEvent e) {
FacesContext context = FacesContext.getCurrentInstance();
String clientId = e.getComponent().getClientId(context);
Map<String, String> requestParams
= context.getExternalContext().getRequestParameterMap();
int x = new Integer((String) requestParams.get(clientId + ".x")).intValue();
int y = new Integer((String) requestParams.get(clientId + ".y")).intValue();
outcome = null;
if (washingtonRect.contains(new Point(x, y)))
outcome = "washington";
if (jeffersonRect.contains(new Point(x, y)))
outcome = "jefferson";
if (rooseveltRect.contains(new Point(x, y)))
outcome = "roosevelt";
if (lincolnRect.contains(new Point(x, y)))
outcome = "lincoln";
}
public String navigate() {
return outcome;
}
}
I dont understand why the author said that, as i tried to use only the action attribute and make a binding to the commandButton, so i modified the index.xhtml and managed bean like that:
New index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<h:outputStylesheet library="css" name="styles.css"/>
<title>#{msgs.indexWindowTitle}</title>
</h:head>
<h:body>
<span class="instructions">#{msgs.instructions}</span>
<h:form>
<h:commandButton image="/resources/images/mountrushmore.jpg" id="commandButton" binding="#{rushmore.command}"
styleClass="imageButton" ac
action="#{rushmore.navigate}"/>
</h:form>
<ui:debug></ui:debug>
</h:body>
</html>
New Managed Bean:
package com.corejsf;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.Map;
import javax.faces.bean.ManagedBean;
// or import javax.inject.Named;
import javax.faces.bean.RequestScoped;
// or import javax.faces.bean.RequestScoped;
import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
#ManagedBean
// or #Named
#RequestScoped
public class Rushmore {
private String outcome = null;
private Rectangle washingtonRect = new Rectangle(70, 30, 40, 40);
private Rectangle jeffersonRect = new Rectangle(115, 45, 40, 40);
private Rectangle rooseveltRect = new Rectangle(135, 65, 40, 40);
private Rectangle lincolnRect = new Rectangle(175, 62, 40, 40);
private UICommand command;
public String navigate() {
FacesContext context = FacesContext.getCurrentInstance();
String clientId = command.getClientId(context);
Map<String, String> requestParams = context.getExternalContext()
.getRequestParameterMap();
int x = new Integer((String) requestParams.get(clientId + ".x"))
.intValue();
int y = new Integer((String) requestParams.get(clientId + ".y"))
.intValue();
outcome = null;
if (washingtonRect.contains(new Point(x, y)))
outcome = "washington";
if (jeffersonRect.contains(new Point(x, y)))
outcome = "jefferson";
if (rooseveltRect.contains(new Point(x, y)))
outcome = "roosevelt";
if (lincolnRect.contains(new Point(x, y)))
outcome = "lincoln";
return outcome;
}
public UICommand getCommand() {
return command;
}
public void setCommand(UICommand command) {
this.command = command;
}
}
So the application worked exactly how it shoul work.
My question is what is the technical advantage (as i know that from a conceptual point of view we must separate business logic from user interface logic) of using actionListner in that example instead of using only action attribute?
This question was answered whithin the comments, So i will copy the response of BalusC:
Nope. It's purely for demonstration purposes. It would only be
beneficial if the outcome part was determined in action instead of in
actionListener. Right now the handleMouseClick() action listener isn't
reusable on different actions expecting a different outcome

creating simple reusable component in Apache Tapestry5

I am starting an adventure with Apache Tapestry5. I am trying to make simple component (for tests), consisting of pair of Textfields. Component is named "TestComp". I have following elements:
testComp.tml
<t:container
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
<p>
<input t:type="TextField" t:id="testOne" t:value="testOne.input"/><br/>
<input t:type="TextField" t:id="testTwo" t:value="testTwo.input"/><br/>
</p>
</t:container>
TestComp.java
public class TestComp {
private DataContainer testOne;
private DataContainer testTwo;
#SetupRender
public void setup(){
testOne = new DataContainer();
testTwo = new DataContainer();
}
public String getContentOfTestOne() {
return testOne.getInput();
}
public String getContentOfTestTwo() {
return testTwo.getInput();
}
public DataContainer getTestOne() {
return testOne;
}
public void setTestOne(DataContainer testOne) {
this.testOne = testOne;
}
public DataContainer getTestTwo() {
return testTwo;
}
public void setTestTwo(DataContainer testTwo) {
this.testTwo = testTwo;
}
}
And then I am trying to use it in other place, for example in index.tml:
<form t:type="form" t:id="out">
<t:testComp />
<br/><input type="submit" value="Component"/>
</form>
According to dozens of materials and examples I've found (to be honest non of it refereed to case similar to mine) such implementation should result of showing testComp element in the form, but unfotrunately there is nothing rendered above the button (though tapestry is not crashing). What am I missing? And will I be able to put in Index.java property of TestComp type and bind it with my
<t:testComp />
in Index.tml by id (or it requires something more to implement in my custom component?)
Did you provide the full index.tml file? If so, you are missing the tapestry namespace as well as a correctly setup html document. Try the following:
Index.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
<head>
<title>My page</title>
</head>
<body>
<form t:type="form" t:id="out">
<div t:id="testComp" />
<br/><input type="submit" value="Component"/>
</form>
</body>
</html>
In your Index.java you can use this to access your component.
#component(id="testComp")
private TestComp testComp;
If this does not work there is probably something wrong in your configuration or setup and you might just be looking at a static tml file not handled by tapestry at all. In this case follow the step-by-step guide on the Getting Started page.

Calling method with variable arguments from JSF 2.0

In a backing bean I declared following method
public boolean hasPermission(Object... objects) {
...
}
And I'm trying to call it from JSF 2.0 as follows:
<c:set var="hasPermission" scope="view" value="#{restrictions.hasPermission(entity)}" />
And it throws
javax.el.ELException: Cannot convert Entity of class com.testing.Entity to class [Ljava.lang.Object;
If I pass two arguments, then it throws
Method hasPermission not found
Can I somehow call varargs methods from JSF 2.0?
Varargs is not officially supported in EL. At least, it's nowhere specified in EL specification. There does also not seem to be any plans to introduce it in the upcoming EL 3.0.
You need to look for a different solution. As the functional requirement is unclear, I can't suggest any one.
Update it seems that the Apache EL parser as supplied in Tomcat supports this. It at least isn't supported by Sun/Oracle EL parser as supplied in Glassfish.
On Tomcat 7 JSF 2.1.4 following works
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h:form>
<h:commandButton value="click 1"
action="#{test.var('a','b',1,test.i,test.d,test.s,test.ss)}"/>
<h:commandButton value="click 2"
action="#{test.var('a','b',1)}"/>
<h:commandButton value="click 3"
action="#{test.var(test.i,test.d,test.s,test.ss)}"/>
</h:form>
</body>
</html>
The Bean:
#ManagedBean
public class Test {
private Integer i = 10;
private Double d = 10.0;
private String s = "varargs";
private String[] ss = new String[]{"1","2","3"};
public Integer getI() {
return i;
}
public void setI(Integer i) {
this.i = i;
}
public Double getD() {
return d;
}
public void setD(Double d) {
this.d = d;
}
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
public String[] getSs() {
return ss;
}
public void setSs(String[] ss) {
this.ss = ss;
}
public void var(Object...objects){
System.out.println(Arrays.toString(objects));
}
}
Output : on click 1,2,3
[a, b, 1, 10, 10.0, varargs, [Ljava.lang.String;#4fa9cba5]
[a, b, 1]
[10, 10.0, varargs, [Ljava.lang.String;#26b923ee]
Is this what you are looking for.... as the way you are trying to call in question is blank.

Resources