Fragments with Expandable List Views - list

I'm making an app that uses an expandable list view in a swipe tab fragment.
I'm also using the android-support v4.jar library.
And I'm getting this error. Anyone could help me?
PorTitulo.java
package com.android.bibliotecautpmovil;
import java.util.HashMap;
import java.util.List;
import com.android.bibliotecautpmovil.R;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
public class PorTitulo extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_titulo, container, false);
ExpandableListView elv = (ExpandableListView) view.findViewById(R.id.lvExp);
elv.setAdapter(new TabsListAdapter()); // **HERE I HAVE THE ERROR**
return view;
}
public class TabsListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader;
private HashMap<String, List<String>> _listDataChild;
public TabsListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
private String[][] children = {
{ "Arnold", "Barry", "Chuck", "David" },
{ "Ace", "Bandit", "Cha-Cha", "Deuce" },
{ "Fluffy", "Snuggles" },
{ "Goldy", "Bubbles" }
};
#Override`enter code here`
public int getGroupCount() {
return this._listDataHeader.size();
}
//
#Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
//
#Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
//
#Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
//
#Override`enter code here`
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/fondoutp" >
<ExpandableListView
android:id="#+id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:cacheColorHint="#00000000"/>
</LinearLayout>
list_group.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#000000">
<TextView
android:id="#+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="17dp"
android:textColor="#f9f93d" />
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" >
<TextView
android:id="#+id/lblListItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#000000"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />
</LinearLayout>

Related

java.lang.ClassCastException: android.app.ReceiverRestrictedContext cannot be cast to android.app.Activity

This is my manifest
<receiver android:name="com.devfret.mobile.Fretlink.receivers.GpsLocationReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.LOCALE_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
At the time I close the gps, I get crash . with this line=>
status.startResolutionForResult( (Activity)ctx , 1000);
my classes which I call this method (CheckAndOpenGps)extends AppCompatActivity .
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
import android.location.LocationManager;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.Toast;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.Result;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationSettingsRequest;
import com.google.android.gms.location.LocationSettingsStatusCodes;
import com.devfret.mobile.Fretlink.R;
public class GpsLocationReceiver extends BroadcastReceiver {
public GpsLocationReceiver() {
}
private GoogleApiClient googleApiClient;
public Context contex;
ContentResolver contentResolver;
// int mode = Settings.Secure.getInt(
// contentResolver, Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
//String locationMode="Gps is not activated";
LocationManager locationManager;
#Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
// throw new UnsupportedOperationException("Not yet implemented");
this.contex = context;
contentResolver = context.getContentResolver();
locationManager = (LocationManager) contex.
getSystemService(Context.LOCATION_SERVICE);
if (!IsGpsStatusActive(locationManager)) {
Toast.makeText(context, "GPS is not working. Please Activate the GPS", Toast.LENGTH_SHORT).show();//emre changed
CheckAndOpenGps(context, googleApiClient);
}
}
public static Boolean IsGpsStatusActive(LocationManager locationManager)//e
{
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
return false;
} else
return true;
}
public static void buildAlertMessageNoGps(final Context ctx, final GoogleApiClient googleApiClient) // emre yazdi
{
final LayoutInflater mInflater = LayoutInflater.from(ctx);
final AlertDialog.Builder builder = new AlertDialog.Builder(mInflater.getContext());
final AlertDialog.Builder builderexit = new AlertDialog.Builder(mInflater.getContext());
builder.setMessage(R.string.gps_off_turn_on).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
#Override
public void onClick(#SuppressWarnings("unused") final DialogInterface dialog, #SuppressWarnings("unused")
final int id) {
CheckAndOpenGps(ctx, googleApiClient);
}
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
#Override
public void onClick(final DialogInterface dialog, #SuppressWarnings("unused") final int id) {
builderexit.setMessage(R.string.canoot_work_without_gps).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
#Override
public void onClick(#SuppressWarnings("unused") final DialogInterface dialog, #SuppressWarnings("unused")
final int id) {
System.exit(0);
}
});
final AlertDialog alertexit = builderexit.create();
alertexit.show();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
public static void CheckAndOpenGps(final Context ctx, GoogleApiClient googleApiClient) {
if (googleApiClient == null) {
googleApiClient = new GoogleApiClient.Builder(ctx).addApi(LocationServices.API).build();
googleApiClient.connect();
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
//locationRequest.setInterval(30 * 1000);//emre 30
locationRequest.setFastestInterval(5 * 1000);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
com.google.android.gms.common.api.PendingResult result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
//final GoogleApiClient finalGoogleApiClient = googleApiClient;
result.setResultCallback(new ResultCallback() {
#Override
public void onResult(#NonNull Result result) {
final Status status = result.getStatus();
Log.d("statusCode", String.valueOf(status.getStatusCode()) + " message " + status.getStatusMessage());
//
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
status.startResolutionForResult( (Activity)ctx , 1000);
} catch (IntentSender.SendIntentException e) {
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
break;
}
}
});
}
}
}
The problem: long story short you are trying to cast BroadcastReceiver's context to Activity here:
status.startResolutionForResult( (Activity)ctx , 1000);
Which is wrong, since those are two unrelated objects.
A solution: since the method does require Activity as a parameter, why not pass the activity there.
I suppose your app does have at least one Activity (if not, you can create one), so just pass the status to it in extras:
ctx.startActivity(new Intent(ctx, YourActivityName.class).putExtra("status-to-resolve", status));
And then in its onCreate() method you can unparcel your status and do the resolution:
Status status = (Status) getIntent().getParcelableExtra("status-to-resolve");
status.startResolutionForResult(this, 1000);

Passing Data from Fragment to Activity in Android

I am using a Fragment as my first screen , I have a button which Onclick has to take to me different activity.
Here is my Code:
HomeFragment.Java:
package info.androidhive.navigationdrawer.fragment;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import info.androidhive.navigationdrawer.R;
public class HomeFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
public HomeFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param param1 Parameter 1.
* #param param2 Parameter 2.
* #return A new instance of fragment HomeFragment.
*/
// TODO: Rename and change types and number of parameters
public static HomeFragment newInstance(String param1, String param2) {
HomeFragment fragment = new HomeFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
// if (context instanceof OnFragmentInteractionListener) {
// mListener = (OnFragmentInteractionListener) context;
// } else {
// throw new RuntimeException(context.toString()
// + " must implement OnFragmentInteractionListener");
// }
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
HomeFragment.XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.navigationdrawer.fragment.HomeFragment">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:alpha="0.3"
android:src="#drawable/ic_home_black_24dp" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</FrameLayout>
Activity.JAVA
package info.androidhive.navigationdrawer.activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import info.androidhive.navigationdrawer.R;
public class ChoseFoodCourt extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_us);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == android.R.id.home) {
// finish the activity
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
}
I have also added the activity in manifest file.
Please help me out adding onclick listener in HomeFragment.JAVA. Not sure where to call onclick listener.
Thanks in advance.
Just use the following code from developers.android.com. There you also will find an explanation how the OnClickListener works.
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.content_layout_id);
final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});
}
}

jaxb: I use different method but all doesn't work

I want to output a XML like this:
<master>
<list type="array" nil="true">
<master>
I have tried #XmlAttribute and #XmlElement(nil=true), how should do this with jaxb.
<slave-status><connect-retry type="integer" nil="true"/>
<created_at type="datetime" nil="true"/>
<slave-status>
Master.java
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
#XmlRootElement
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "master", propOrder = {
"list"
})
public class Master {
#XmlElement(name = "list")
protected List list;
public List getList() {
return list;
}
public void setList(List value) {
this.list = value;
}
}
List.java
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "list")
public class List {
#XmlAttribute(name = "type")
protected String type;
#XmlAttribute(name = "nil")
protected boolean nil;
public boolean isNil() {
return nil;
}
public void setNil(boolean nil) {
this.nil = nil;
}
public String getType() {
return type;
}
public void setType(String value) {
this.type = value;
}
}
package-info.java
#javax.xml.bind.annotation.XmlSchema(namespace = "", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.ca.exporter.util;
Main.java
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
public class Main {
public static void main(String[] args) throws JAXBException {
JAXBContext jc = JAXBContext.newInstance(Master.class);
Master m = new Master();
List l = new List();
l.setType("array");
l.setNil(true);
m.setList(l);
Marshaller mar = jc.createMarshaller();
mar.marshal(m, System.out);
}
}
Output - XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<master>
<list type="array" nil="true"/>
</master>

getFragmentManager to Fragment

I am trying to convert an activity to a fragment and have problems with getFragmentManager.
my xml file:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context="xpak.probandosidebar.MapsFragment"
class ="com.google.android.gms.maps.SupportMapFragment" />
and my java file:
public class MapsFragment extends Fragment {
private GoogleMap mMap;
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment_maps,container,false);
}
#Override
public void onStart() {
super.onStart();
setUpMapIfNeeded();
}
#Override
public void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
if (mMap == null) {
//here is the error
mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}}
the error is: cannot cast android.app.Fragment to com.google.android.gms.maps.SupportMapFragment
I searched everywhere without success , I hope you can help me
greetings from chile
Try doing this
<com.google.android.gms.maps.SupportMapFragment
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context="xpak.probandosidebar.MapsFragment"
class ="com.google.android.gms.maps.SupportMapFragment" />

show and modify List in grid ZK

I have a list that is dynamically generated from the view.
when the button is clicked, a new row is added, the value is entered and saved.
.zul
<zk>
<window border="normal" title="hello" viewModel="#id('vm') #init('gemalto.CreateServiceVersion')" apply="org.zkoss.bind.BindComposer">
<grid id="demoGrid"
model="#load(vm.profileList) #template((each.editingStatus) ? 'editable' : 'noneditable')">
<columns sizable="true">
<column width="160px" >Value</column>
<column width="160px" ></column>
</columns>
<rows>
<template name="editable">
<row>
<textbox id="valueTextBox"
value="#load(each.serviceProfile.valueVariable) #save(each.serviceProfile.valueVariable, before='confirm')" />
<button
image="/img/save.png" label="save"
onClick="#command('confirm', currentVariable=each)"/>
</row>
</template>
<template name="noneditable">
<row>
<label value="#load(each.serviceProfile.valueVariable)" />
</row>
</template>
</rows>
</grid>
<div align="center">
<button label="Add" image="/img/create.png" onClick="#command('onAddNew')" />
</div>
</window>
</zk>
view model
public class CreateServiceVersion extends SelectorComposer<Component> {
private boolean isEditing = false;
private boolean displayEdit = true;
private boolean isAddNew = false;
private List<ServiceProfileStatus> profileList = new ArrayList<ServiceProfileStatus>();
public List<ServiceProfileStatus> getProfileList() {
return profileList;
}
#AfterCompose
public void afterCompose() {
profileList.add(new ServiceProfileStatus(new ServiceProfile("value1"), false));
profileList.add(new ServiceProfileStatus(new ServiceProfile("value2"), false));
}
#Command
public void CrudServiceVersion() {
Executions.sendRedirect("CrudServiceVersion.zul");
}
#Command
#NotifyChange({"profileList"})
public void onAddNew() {
if (!isEditing) {
ServiceProfileStatus sps = new ServiceProfileStatus(new ServiceProfile(""), displayEdit);
profileList.add(0, sps);
isAddNew = true;
isEditing = true;
}
}
#Command
public void confirm(#BindingParam("currentVariable") ServiceProfileStatus sps) {
isEditing = false;
isAddNew = false;
sps.setEditingStatus(isEditing);
BindUtils.postNotifyChange(null,null,sps,"*");
}
}
the problem is that I add a new item, the value is copied to all others items.
I put the images to see more clearly what is happening.
imgur.com/7u7OkPG
imgur.com/mf8PUYI
imgur.com/aJpNoXM
I tested with your code and it works normally with me.
Now I changed the code a little bit :
Removed the extends SelectorComposer from your viewmodel cause that is not needed for MVVM.
Changed your 2 templates to 1 template.
Usage of your boolean in your viewmodel in the zul.
Zul :
<?xml version="1.0" encoding="UTF-8"?>
<zk>
<window border="normal" title="hello" viewModel="#id('vm') #init('be.chillworld.CreateServiceVersion')" apply="org.zkoss.bind.BindComposer">
<grid id="demoGrid" model="#load(vm.profileList)">
<columns sizable="true">
<column width="160px" >Value</column>
<column width="160px" ></column>
</columns>
<rows>
<template name="model">
<row>
<textbox value="#load(each.serviceProfile.valueVariable) #save(each.serviceProfile.valueVariable, before='confirm')" />
<button disabled="#load(not each.editingStatus)" visible="#load(each.editingStatus)" image="/img/save.png" label="save"
onClick="#command('confirm', currentVariable=each)"/>
</row>
</template>
</rows>
</grid>
<div align="center">
<button disabled="#load(vm.mayCreateNew)" label="Add" image="/img/create.png" onClick="#command('onAddNew')" />
</div>
</window>
</zk>
Viewmodel :
package be.chillworld;
import java.util.ArrayList;
import java.util.List;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Executions;
/**
*
* #author chillworld */
public class CreateServiceVersion {
private boolean isEditing = false;
private List<ServiceProfileStatus> profileList = new ArrayList<ServiceProfileStatus>();
public List<ServiceProfileStatus> getProfileList() {
return profileList;
}
#AfterCompose
public void afterCompose() {
profileList.add(new ServiceProfileStatus(new ServiceProfile("value1"), false));
profileList.add(new ServiceProfileStatus(new ServiceProfile("value2"), false));
}
#Command
public void CrudServiceVersion() {
Executions.sendRedirect("CrudServiceVersion.zul");
}
#Command
#NotifyChange({"profileList","mayCreateNew"})
public void onAddNew() {
isEditing = true;
ServiceProfileStatus sps = new ServiceProfileStatus(new ServiceProfile(""), true);
profileList.add(0, sps);
}
#Command
#NotifyChange("mayCreateNew")
public void confirm(#BindingParam("currentVariable") ServiceProfileStatus sps) {
isEditing = false;
sps.setEditingStatus(isEditing);
BindUtils.postNotifyChange(null, null, sps, "*");
}
public boolean getMayCreateNew() {
return isEditing;
}
}
ServiceProfileStatus.java :
package be.chillworld;
/**
*
* #author chillworld
*/
public class ServiceProfileStatus {
private ServiceProfile serviceProfile;
private boolean editingStatus;
public ServiceProfileStatus(ServiceProfile serviceProfile, boolean editingStatus) {
this.serviceProfile = serviceProfile;
this.editingStatus = editingStatus;
}
public boolean isEditingStatus() {
return editingStatus;
}
public void setEditingStatus(boolean editingStatus) {
this.editingStatus = editingStatus;
}
public ServiceProfile getServiceProfile() {
return serviceProfile;
}
public void setServiceProfile(ServiceProfile serviceProfile) {
this.serviceProfile = serviceProfile;
}
public ServiceProfileStatus(ServiceProfile serviceProfile) {
this.serviceProfile = serviceProfile;
}
}
ServiceProfile.java :
package be.chillworld;
/**
*
* #author chillworld
*/
public class ServiceProfile {
private String valueVariable;
public ServiceProfile(String valueVariable) {
this.valueVariable = valueVariable;
}
public String getValueVariable() {
return valueVariable;
}
public void setValueVariable(String valueVariable) {
this.valueVariable = valueVariable;
}
}