LWUIT Event Handling - java-me

In a LWUIT form when I Command Listener and when I use Action Listener ,give me a example.In a lWUIT form how to go one from to another form when I click a Button.Please give me a code regarding this.

command Lister is default j2me library class while ActionListner is lwuit class,
i reccomend to use ActionListner
example
declare class as
see this example Introduction_to_Lightweight_User_Interface_Toolkit
EDIT
public void actionPerformed(ActionEvent event) {
if(event.getSource() == nyButton){
Form secondForm = new Form();
secondForm.show();
}
}

Related

JSF Custom component extending Primefaces SelectOneMenu

I need to create a custom component that either extend or include a Primefaces SelectOneMenu. This is done so that I can deliver the select items based on the field (for now, they are hardcoded in the example below and the tag is properly registered).
The component is rendered and the select items are also displayed fine. However, when I save, the record's field is not updated with the selected item's value. Is there some primeface method I should override to actually set the value?
Are there any tutorials on how to extend primeface (or atleast jsf) components? I could hardly find any. Thank you in advance
#FacesComponent(value = ComponentRegistry.INPUT_SELECTDROPDOWN_COMPONENT_TYPE)
public class InputSelectDropdown extends SelectOneMenu {
#Override
public void encodeBegin(FacesContext context) throws IOException {
this.setValueExpression("value", this.getValueExpression("value"));
UISelectItem select1 = new UISelectItem();
select1.setItemLabel("item 1");
select1.setItemValue("item1");
select1.encodeAll(context);
this.getChildren().add(select1);
UISelectItem select2 = new UISelectItem();
select2.setItemLabel("item 2");
select2.setItemValue("item2");
select2.encodeAll(context);
this.getChildren().add(select2);
super.encodeBegin(context);
}
}

How to add a custom component from encodebegin?

I've created a custom component which extends the UIComponentBase abstract class, so when I use this component: <test:mycomponent /> It works as espected.
I'm creating another custom component and I want to use the previously created component in this one, so I tried:
#Override
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("mycomponent", this);
writer.endElement("mycomponent");
}
I new this was a long shot, since startElement just creates a tag with the given component name i.e mycomponent, so I searched around and found:
UIComponentBase mycomponent =
(UIComponentBase)context.getApplication().createComponent("mycomponent");
If this is correct, how does one add the component ? I'm using JSF 2.2
A link to where I can find more on this would be greatly apreciated also.

How to programatically open a dialog box in primefaces without user click?

I am working on an exam management session using Java EE 7 and Primefaces. Tests are timed and once the time is over, I want to display a dialog box automatically(i.e. without user clicking any button). I successfully used Primefaces Dialog framework on the click of a button, but can't do it automatically.
For timing the test I am using TimerService, which calls a stateless EJB's method on timeout. I have a session scoped CDI bean which creates the timer.
This is the post construct method of the CDI bean.
public void init() {
studentAnswers = new ArrayList<StudentAnswer>();
examSections=ePaper.getSections();
examTimerBean.createExamPaperDuration(10,RequestContext.getCurrentInstance());
}
The stateless EJB is as follows -
#Stateless
public class ExamTimerBean {
#Resource TimerService timerService;
RequestContext reqCtx;
public void createExamPaperDuration(int duration,RequestContext reqCtx){
this.reqCtx=reqCtx;
timerService.createTimer(duration*1000, null);
}
#Timeout
public void examTimeExpired(){// throws IOException{
try{
reqCtx.openDialog("thanks");
}
catch(EJBException e){
System.out.println(e.getMessage());
}
}
}
I am passing the request context to the EJB, but the dialogBox doesn't open. Kindly help.

How to make a check box editable

Domino 8.5.3 FP5, Designer 9.0.1.
I have an empty xpage containing only the following checkbox. I am not able to make it editable. It show the right value, but appear as disabled.
<xp:checkBox text="Label" id="checkBox1" uncheckedValue="true"
checkedValue="false"
value="#{javascript:jBeanConfigSupport.validationEnabledTxt}">
</xp:checkBox>
If I remove the binding to Java bean, all run fine. This is the Java bean code (part)
private boolean isValidationEnabled=true;
public String getValidationEnabledTxt() {
return String.valueOf(isValidationEnabled);
}
public void setValidationEnabledTxt(String onOff) {
isValidationEnabled=Boolean.parseBoolean(onOff);
}
public void setValidationEnabledTxt(boolean onOff) {
isValidationEnabled=onOff;
}
Where Am I wrong?
You're binding using SSJS, so instead of binding to the validationEnabledTxt property of your bean, the result of jBeanConfigSupport.validationEnabledTxt is being used to determine what it should be bound to. value="#{jBeanConfigSupport.validationEnabledTxt}" should work to map to the getter and setter.
Francesco,
You need to have a working setter method for this to be editable. In your case there is probably a problem with the setValidationEnabledTxt() method that is causing the field in the UI to be readonly.
Try adding "this" to your code so that it reads this.isValidationEnables = Boolean.parseBoolean(onOff);

While typing in a text field enable a keystroke ENTER to activate a button in JavaFX

Such as typing into the Google search box the hitting ENTER activates the search
I've just been introduced to JavaFX and Scene Builder a few days ago so I'm learning the basics here. I have the latest version of JavaFX and am using Scene Builder to facilitate action events. Also, any pointers to relevant tutorials would be helpful. At one point in the day I was focused on the Keyboard section of the coding panel of Scene Builder, especially with the "On Key Released" event with no results. Thanks in advance
Here's a rough idea of what I'm trying to do:
#FXML
Text Field theTextField;
#FXML
Button theButton;
#FXML
void ButtonPressed() {
//do stuff here
}
#FXML
//when ENTER is pressed the button is activated
void textFieldEnterPressed() {
ButtonPressed();
}
In your FXML file, add a onKeyPressed handler
<TextField fx:id="yourTextField" onKeyPressed="#handleEnterPressed">
Implement the handler in you Controller
#FXML
public void handleEnterPressed(KeyEvent event)
if (event.getCode() == KeyCode.ENTER) {
// do some actions
}
}
In TextField, when you press Enter, you get notification through onAction. In your Java code you can add:
#FXML
private void handleTFAction(ActionEvent event) {
TextField source = (TextField)event.getSource();
System.out.println("You entered: "+source.getText());
}
In your FXML (or through JavaFX SceneBuilder designer) hook it up to your TextField's OnAction event. In FXML it looks something like this:
<TextField onAction="#handleTFAction" ... />

Resources